package pl.edu.pw.ee.buildcity.services;

import org.apache.log4j.Logger;
import pl.edu.pw.ee.buildcity.dao.GenericDao;
import pl.edu.pw.ee.buildcity.entities.BuildDefinition;

import javax.annotation.Resource;
import javax.persistence.EntityNotFoundException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author mgrzechocinski
 * @since 2009-10-18
 */
public class BuildDefinitionService extends GenericEntityService<BuildDefinition, Long> {

	private static final Logger log = Logger.getLogger(BuildDefinitionService.class);

	@Resource(name = "jpaGenericDao")
	private GenericDao<BuildDefinition, Long> dao;

	public BuildDefinition getByName(String name) {
		BuildDefinition foundBuildDefinition = null;
		try {
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("name", name);

			foundBuildDefinition = dao.getSingleResultOfNamedQuery("findBuildDefinitionByName", params);
		} catch (EntityNotFoundException e) {
			log.warn("Could not find build definition with name " + name);
		}
		return foundBuildDefinition;
	}

	public List<BuildDefinition> getAll() {
		return super.getAll(BuildDefinition.class);
	}

}
